'''
Created on 31/08/2009

@author: eh01
'''
from ConfigParser import RawConfigParser
from Queue import Queue, Empty
from datastore import database
from datastore.database import DataStore
from datastore.resource import Resource, ResourceDict
from runtime import rt
from runtime.spaces import Spaces, SpacesContext
from spear.a2atask import A2ATask
from spear.wsdl import WSDL
import base64
import logging
import os
import time
import unittest

LOGGING = logging.WARNING  # logging.DEBUG
ENVIRONMENT = 'uat'

class A2ATaskTest(unittest.TestCase):

    def setUp(self):
        queue = Queue()
        self.spaces = Spaces()
        spaces_context = SpacesContext(self.spaces, queue)
        runtime = rt.Runtime()
        runtime.initialise_spaces_with_local_config_files(spaces_context)       

        self.temp_database_name = 'test.db'
        self.original_database_name = database.DATABASE_NAME
        database.DATABASE_NAME = self.temp_database_name
        
        section = 'a2a data'
        self.cp = RawConfigParser()
        # the code coverage test does some magic when executing. And the properties_file_path has to be change to use the one below
        # which only just specifies the file name
#        properties_file_path = 'a2a.properties'
        properties_file_path = os.path.dirname(__file__) + '/a2a.properties'
        self.cp.read(properties_file_path)
        self.client_cert_file_name = self.cp.get(section, 'clientcertfilename')
        self.client_cert_password = self.cp.get(section, 'clientcertpassword')
        self.spear_user_username = self.cp.get(section, 'spearuserusername')
        self.spear_user_password = self.cp.get(section, 'spearuserpassword')
        self.spear_user_remote_user = self.cp.get(section, 'spearuserremoteuser')
        self.spear_user_access_level = self.cp.get(section, 'spearuseraccesslevel')
        self.wsdl_path = self.cp.get(section, 'wsdlpath')
        self.attachments_path = self.cp.get(section, 'attachmentspath')
        
        
    def tearDown(self):
        try:
            os.remove(self.temp_database_name)
        except:
            pass     

    def test_parse_soap_response_case_1(self):
        '''[a2atask] parse_soap_response when there is only one entry in a collection. This will test that
        our soap parser will put the one entry in a array even though there is one entry.'''
        queue = Queue()
        spaces_context = SpacesContext(self.spaces, queue)
        uri_tasks = self.spaces.uri('tasks:')
        uri_datastore = self.spaces.uri('datastore:')
        uri_spear = self.spaces.uri('spear:')
        rs_wsdl = self.create_wsdl_resource('LxSpearApplicationList', uri_datastore, uri_spear)
        ds = DataStore(self.spaces.ns)
        ds.put([rs_wsdl])
        # dummy task def resource
        task_def_resource = Resource()                
        a2a_task = A2ATask(self.spaces, uri_tasks.eplanning.spear.a2atask, task_def_resource)
        soap_response='''
        <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <soapenv:Header />
    <soapenv:Body>
        <p625:getAllResponse xmlns:p625="http://was6.webservice.spear.lx.dse.vic.gov.au">
            <p625:getAllReturn
                xmlns:p27="http://response.webservice.spear.lx.dse.vic.gov.au"
                xmlns:p526="http://application.response.was6.webservice.spear.lx.dse.vic.gov.au">
                <p27:responseType>
                    <p27:code>000</p27:code>
                    <p27:message>Error key: S2-a2a-252-4224 null</p27:message>
                </p27:responseType>
                <p526:applications>
                    <p526:actionRequired>0</p526:actionRequired>
                    <p526:address>154 BOURKE STREET, MELBOURNE 3000</p526:address>
                    <p526:advertisingRequiredFlag>0</p526:advertisingRequiredFlag>
                    <p526:applicantName>Richard Applicant</p526:applicantName>
                    <p526:applicationStatus>Referred</p526:applicationStatus>
                    <p526:applicationType>JOINT</p526:applicationType>
                    <p526:councilName xsi:nil="true" />
                    <p526:councilReferenceNumber>11</p526:councilReferenceNumber>
                    <p526:fullAddress>154 BOURKE STREET, MELBOURNE 3000</p526:fullAddress>
                    <p526:councilHosted>0</p526:councilHosted>
                    <p526:permitSpearRef xsi:nil="true" />
                    <p526:planNumber>PS703520E</p526:planNumber>
                    <p526:raReferenceNumber xsi:nil="true" />
                    <p526:spearReference>S000255A</p526:spearReference>
                    <p526:streetName>BOURKE</p526:streetName>
                    <p526:submittedDate>2007-10-23</p526:submittedDate>
                    <p526:applicationCcVersion>0</p526:applicationCcVersion>
                </p526:applications>
            </p625:getAllReturn>
        </p625:getAllResponse>
    </soapenv:Body>
</soapenv:Envelope>'''
        result = a2a_task.parse_soap_response(soap_response, spaces_context, 'LxSpearApplicationList')
        self.assertEqual(result.getAllResponse.getAllReturn.responseType.code, '000')
        self.assertEqual(result.getAllResponse.getAllReturn.applications[0].actionRequired, '0')      
        self.assertEqual(result.getAllResponse.getAllReturn.applications[0].address, '154 BOURKE STREET, MELBOURNE 3000')
        self.assertEqual(result.getAllResponse.getAllReturn.applications[0].advertisingRequiredFlag, '0')
        self.assertEqual(result.getAllResponse.getAllReturn.applications[0].applicantName, 'Richard Applicant')
        self.assertEqual(result.getAllResponse.getAllReturn.applications[0].applicationStatus, 'Referred')
        self.assertEqual(result.getAllResponse.getAllReturn.applications[0].applicationType, 'JOINT')
        self.assertEqual(result.getAllResponse.getAllReturn.applications[0].councilName, None)
        self.assertEqual(result.getAllResponse.getAllReturn.applications[0].councilReferenceNumber, '11')
        self.assertEqual(result.getAllResponse.getAllReturn.applications[0].fullAddress, '154 BOURKE STREET, MELBOURNE 3000')
        self.assertEqual(result.getAllResponse.getAllReturn.applications[0].councilHosted, '0')
        self.assertEqual(result.getAllResponse.getAllReturn.applications[0].permitSpearRef, None)
        self.assertEqual(result.getAllResponse.getAllReturn.applications[0].planNumber, 'PS703520E')
        self.assertEqual(result.getAllResponse.getAllReturn.applications[0].raReferenceNumber, None)
        self.assertEqual(result.getAllResponse.getAllReturn.applications[0].spearReference, 'S000255A')
        self.assertEqual(result.getAllResponse.getAllReturn.applications[0].streetName, 'BOURKE')
        self.assertEqual(result.getAllResponse.getAllReturn.applications[0].submittedDate, '2007-10-23')
        self.assertEqual(result.getAllResponse.getAllReturn.applications[0].applicationCcVersion, '0')  
        
    def test_parse_soap_response_case_2(self):
        '''[a2atask] parse_soap_response. This will test that we can handle arrays that have multiple entries.'''
        queue = Queue()
        spaces_context = SpacesContext(self.spaces, queue)
        uri_tasks = self.spaces.uri('tasks:')
        uri_datastore = self.spaces.uri('datastore:')
        uri_spear = self.spaces.uri('spear:')
        rs_wsdl = self.create_wsdl_resource('LxSpearApplicationList', uri_datastore, uri_spear)
        ds = DataStore(self.spaces.ns)
        ds.put([rs_wsdl])
        # dummy task def resource
        task_def_resource = Resource()                
        a2a_task = A2ATask(self.spaces, uri_tasks.eplanning.spear.a2atask, task_def_resource)
        soap_response='''
        <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <soapenv:Header />
    <soapenv:Body>
        <p625:getAllResponse xmlns:p625="http://was6.webservice.spear.lx.dse.vic.gov.au">
            <p625:getAllReturn
                xmlns:p27="http://response.webservice.spear.lx.dse.vic.gov.au"
                xmlns:p526="http://application.response.was6.webservice.spear.lx.dse.vic.gov.au">
                <p27:responseType>
                    <p27:code>000</p27:code>
                    <p27:message>Error key: S2-a2a-252-4224 null</p27:message>
                </p27:responseType>
                <p526:applications>
                    <p526:actionRequired>0</p526:actionRequired>
                    <p526:address>154 BOURKE STREET, MELBOURNE 3000</p526:address>
                    <p526:advertisingRequiredFlag>0</p526:advertisingRequiredFlag>
                    <p526:applicantName>Richard Applicant</p526:applicantName>
                    <p526:applicationStatus>Referred</p526:applicationStatus>
                    <p526:applicationType>JOINT</p526:applicationType>
                    <p526:councilName xsi:nil="true" />
                    <p526:councilReferenceNumber>11</p526:councilReferenceNumber>
                    <p526:fullAddress>154 BOURKE STREET, MELBOURNE 3000</p526:fullAddress>
                    <p526:councilHosted>0</p526:councilHosted>
                    <p526:permitSpearRef xsi:nil="true" />
                    <p526:planNumber>PS703520E</p526:planNumber>
                    <p526:raReferenceNumber xsi:nil="true" />
                    <p526:spearReference>S000255A</p526:spearReference>
                    <p526:streetName>BOURKE</p526:streetName>
                    <p526:submittedDate>2007-10-23</p526:submittedDate>
                    <p526:applicationCcVersion>0</p526:applicationCcVersion>
                </p526:applications>
                <p526:applications>
                    <p526:actionRequired>0</p526:actionRequired>
                    <p526:address>46 GREENOCH COURT, KEILOR DOWNS 3038</p526:address>
                    <p526:advertisingRequiredFlag>0</p526:advertisingRequiredFlag>
                    <p526:applicantName>Adam Beckham</p526:applicantName>
                    <p526:applicationStatus>Referred</p526:applicationStatus>
                    <p526:applicationType>CERTIFICATION</p526:applicationType>
                    <p526:councilName xsi:nil="true" />
                    <p526:councilReferenceNumber>cvxb</p526:councilReferenceNumber>
                    <p526:fullAddress>46 GREENOCH COURT, KEILOR DOWNS 3038</p526:fullAddress>
                    <p526:councilHosted>0</p526:councilHosted>
                    <p526:permitSpearRef xsi:nil="true" />
                    <p526:planNumber>PS702820W</p526:planNumber>
                    <p526:raReferenceNumber xsi:nil="true" />
                    <p526:spearReference>S000007S</p526:spearReference>
                    <p526:streetName>GREENOCH</p526:streetName>
                    <p526:submittedDate>2005-03-08</p526:submittedDate>
                    <p526:applicationCcVersion>0</p526:applicationCcVersion>
                </p526:applications>
                <p526:applications>
                    <p526:actionRequired>1</p526:actionRequired>
                    <p526:address>12 MACQUARIE ROAD, TOORAK 3142</p526:address>
                    <p526:advertisingRequiredFlag>0</p526:advertisingRequiredFlag>
                    <p526:applicantName>Adam Ronaldo</p526:applicantName>
                    <p526:applicationStatus>CouncilDecisionPending</p526:applicationStatus>
                    <p526:applicationType>JOINT</p526:applicationType>
                    <p526:councilName xsi:nil="true" />
                    <p526:councilReferenceNumber>Mtest2</p526:councilReferenceNumber>
                    <p526:fullAddress>12 MACQUARIE ROAD, TOORAK 3142</p526:fullAddress>
                    <p526:councilHosted>0</p526:councilHosted>
                    <p526:permitSpearRef xsi:nil="true" />
                    <p526:planNumber>PS704001A</p526:planNumber>
                    <p526:raReferenceNumber xsi:nil="true" />
                    <p526:spearReference>S000337T</p526:spearReference>
                    <p526:streetName>MACQUARIE</p526:streetName>
                    <p526:submittedDate>2008-08-29</p526:submittedDate>
                    <p526:applicationCcVersion>0</p526:applicationCcVersion>
                </p526:applications>
            </p625:getAllReturn>
        </p625:getAllResponse>
    </soapenv:Body>
</soapenv:Envelope>'''
        result = a2a_task.parse_soap_response(soap_response, spaces_context, 'LxSpearApplicationList')
        self.assertEqual(result.getAllResponse.getAllReturn.responseType.code, '000')
        self.assertEqual(result.getAllResponse.getAllReturn.applications[0].actionRequired, '0')      
        self.assertEqual(result.getAllResponse.getAllReturn.applications[0].address, '154 BOURKE STREET, MELBOURNE 3000')
        self.assertEqual(result.getAllResponse.getAllReturn.applications[0].advertisingRequiredFlag, '0')
        self.assertEqual(result.getAllResponse.getAllReturn.applications[0].applicantName, 'Richard Applicant')
        self.assertEqual(result.getAllResponse.getAllReturn.applications[0].applicationStatus, 'Referred')
        self.assertEqual(result.getAllResponse.getAllReturn.applications[0].applicationType, 'JOINT')
        self.assertEqual(result.getAllResponse.getAllReturn.applications[0].councilName, None)
        self.assertEqual(result.getAllResponse.getAllReturn.applications[0].councilReferenceNumber, '11')
        self.assertEqual(result.getAllResponse.getAllReturn.applications[0].fullAddress, '154 BOURKE STREET, MELBOURNE 3000')
        self.assertEqual(result.getAllResponse.getAllReturn.applications[0].councilHosted, '0')
        self.assertEqual(result.getAllResponse.getAllReturn.applications[0].permitSpearRef, None)
        self.assertEqual(result.getAllResponse.getAllReturn.applications[0].planNumber, 'PS703520E')
        self.assertEqual(result.getAllResponse.getAllReturn.applications[0].raReferenceNumber, None)
        self.assertEqual(result.getAllResponse.getAllReturn.applications[0].spearReference, 'S000255A')
        self.assertEqual(result.getAllResponse.getAllReturn.applications[0].streetName, 'BOURKE')
        self.assertEqual(result.getAllResponse.getAllReturn.applications[0].submittedDate, '2007-10-23')
        self.assertEqual(result.getAllResponse.getAllReturn.applications[0].applicationCcVersion, '0')
        self.assertEqual(result.getAllResponse.getAllReturn.applications[1].actionRequired, '0')        
        self.assertEqual(result.getAllResponse.getAllReturn.applications[1].address, '46 GREENOCH COURT, KEILOR DOWNS 3038')
        self.assertEqual(result.getAllResponse.getAllReturn.applications[1].advertisingRequiredFlag, '0')
        self.assertEqual(result.getAllResponse.getAllReturn.applications[1].applicantName, 'Adam Beckham')
        self.assertEqual(result.getAllResponse.getAllReturn.applications[1].applicationStatus, 'Referred')
        self.assertEqual(result.getAllResponse.getAllReturn.applications[1].applicationType, 'CERTIFICATION')
        self.assertEqual(result.getAllResponse.getAllReturn.applications[1].councilName, None)
        self.assertEqual(result.getAllResponse.getAllReturn.applications[1].councilReferenceNumber, 'cvxb')
        self.assertEqual(result.getAllResponse.getAllReturn.applications[1].fullAddress, '46 GREENOCH COURT, KEILOR DOWNS 3038')
        self.assertEqual(result.getAllResponse.getAllReturn.applications[1].councilHosted, '0')
        self.assertEqual(result.getAllResponse.getAllReturn.applications[1].permitSpearRef, None)
        self.assertEqual(result.getAllResponse.getAllReturn.applications[1].planNumber, 'PS702820W')
        self.assertEqual(result.getAllResponse.getAllReturn.applications[1].raReferenceNumber, None)
        self.assertEqual(result.getAllResponse.getAllReturn.applications[1].spearReference, 'S000007S')
        self.assertEqual(result.getAllResponse.getAllReturn.applications[1].streetName, 'GREENOCH')
        self.assertEqual(result.getAllResponse.getAllReturn.applications[1].submittedDate, '2005-03-08')
        self.assertEqual(result.getAllResponse.getAllReturn.applications[1].applicationCcVersion, '0')        
        self.assertEqual(result.getAllResponse.getAllReturn.applications[2].actionRequired, '1')        
        self.assertEqual(result.getAllResponse.getAllReturn.applications[2].address, '12 MACQUARIE ROAD, TOORAK 3142')
        self.assertEqual(result.getAllResponse.getAllReturn.applications[2].advertisingRequiredFlag, '0')
        self.assertEqual(result.getAllResponse.getAllReturn.applications[2].applicantName, 'Adam Ronaldo')
        self.assertEqual(result.getAllResponse.getAllReturn.applications[2].applicationStatus, 'CouncilDecisionPending')
        self.assertEqual(result.getAllResponse.getAllReturn.applications[2].applicationType, 'JOINT')
        self.assertEqual(result.getAllResponse.getAllReturn.applications[2].councilName, None)
        self.assertEqual(result.getAllResponse.getAllReturn.applications[2].councilReferenceNumber, 'Mtest2')
        self.assertEqual(result.getAllResponse.getAllReturn.applications[2].fullAddress, '12 MACQUARIE ROAD, TOORAK 3142')
        self.assertEqual(result.getAllResponse.getAllReturn.applications[2].councilHosted, '0')
        self.assertEqual(result.getAllResponse.getAllReturn.applications[2].permitSpearRef, None)
        self.assertEqual(result.getAllResponse.getAllReturn.applications[2].planNumber, 'PS704001A')
        self.assertEqual(result.getAllResponse.getAllReturn.applications[2].raReferenceNumber, None)
        self.assertEqual(result.getAllResponse.getAllReturn.applications[2].spearReference, 'S000337T')
        self.assertEqual(result.getAllResponse.getAllReturn.applications[2].streetName, 'MACQUARIE')
        self.assertEqual(result.getAllResponse.getAllReturn.applications[2].submittedDate, '2008-08-29')
        self.assertEqual(result.getAllResponse.getAllReturn.applications[2].applicationCcVersion, '0')          
    
    def test_cb_generate_a2a_request_input_case_1(self):
        '''[a2atask] cb_generate_a2a_request_input_case_1. '''
        expected_soap_message = '''<?xml version="1.0" encoding="utf-8" ?><ns0:Envelope xmlns:ns0="http://schemas.xmlsoap.org/soap/envelope/"><ns0:Body><ns1:echo xmlns:ns1="http://was6.webservice.spear.lx.dse.vic.gov.au"><ns1:accessToken><ns2:accessLevel xmlns:ns2="http://access.webservice.spear.lx.dse.vic.gov.au">{0}</ns2:accessLevel><ns2:hostId xmlns:ns2="http://access.webservice.spear.lx.dse.vic.gov.au">{1}</ns2:hostId><ns2:hostPassword xmlns:ns2="http://access.webservice.spear.lx.dse.vic.gov.au">{2}</ns2:hostPassword><ns2:remoteUser xmlns:ns2="http://access.webservice.spear.lx.dse.vic.gov.au">{3}</ns2:remoteUser></ns1:accessToken><ns1:input>Hello, World!</ns1:input></ns1:echo></ns0:Body></ns0:Envelope>'''.format(self.spear_user_access_level, self.spear_user_username, self.spear_user_password, self.spear_user_remote_user)
        uri_tasks = self.spaces.uri('tasks:')
        uri_spear = self.spaces.uri('spear:')
        uri_a2a = self.spaces.uri('a2a:')
        uri_datastore = self.spaces.uri('datastore:')
        content_as_string = open(self.client_cert_file_name, 'rb').read()
        client_cert = Resource()
        client_cert.content = content_as_string
        client_cert.set_metadata(uri_datastore.resource.type, uri_spear.type.client_cert)
        client_cert.set_metadata(uri_spear.cert.password, self.client_cert_password)
        webservice_parameter = ResourceDict()
        echo = [] 
        webservice_parameter['echo'] = echo 
        access_token_elements = [{'accessLevel':self.spear_user_access_level},
                                  {'hostId':self.spear_user_username},
                                  {'hostPassword':self.spear_user_password},
                                  {'remoteUser':self.spear_user_remote_user}]
        echo.append({'accessToken':access_token_elements})
        echo.append({'input':'Hello, World!'})
        res = Resource()
        res.data = webservice_parameter
        res.environment = ENVIRONMENT
        wsdl_file = open(self.wsdl_path + 'LxSpearEcho.wsdl', 'rb')
        wsdl_string = wsdl_file.read()
        wsdl_file.close()
        wsdl_file = None
        wsdl = WSDL(wsdl_string)
        rs_wsdl = Resource()
        rs_wsdl.element_dictionary = wsdl.element_dictionary
        rs_wsdl.set_metadata(uri_datastore.resource.type, uri_spear.type.wsdl)
        rs_wsdl.set_metadata(uri_spear.wsdl.name, 'LxSpearEcho')
        ds = DataStore()
        ds.put([rs_wsdl, client_cert])  
        consumer_queue = Queue()     
        consumer_spaces_context = SpacesContext(self.spaces, consumer_queue)
        # dummy task def resource
        task_def_resource = Resource()                
        a2a_task = A2ATask(self.spaces, uri_tasks.eplanning.spear.a2atask, task_def_resource)
        (is_return, uri) = a2a_task.cb_generate_a2a_request_input('put', uri_a2a.ws.LxSpearEcho.echo.collection(True), res, None, a2a_task.context)
        self.assertTrue(is_return)
        res = consumer_spaces_context.get(uri)
        self.assertTrue(res.soap_message.replace('\r\n', '') == expected_soap_message)        

    def test_cb_issue_a2a_request_case_1(self):
        '''[a2atask] cb_issue_a2a_request_case_1. '''
        content_as_string = open(self.client_cert_file_name, 'rb').read()
        uri_tasks = self.spaces.uri('tasks:')
        uri_spear = self.spaces.uri('spear:')
        uri_a2a = self.spaces.uri('a2a:')
        uri_datastore = self.spaces.uri('datastore:')        
        client_cert = Resource()
        client_cert.content = content_as_string
        client_cert.set_metadata(uri_datastore.resource.type, uri_spear.type.client_cert)
        client_cert.set_metadata(uri_spear.cert.password, self.client_cert_password)
        ws_name = 'LxSpearEcho'
        rs_wsdl = self.create_wsdl_resource(ws_name, uri_datastore, uri_spear)
        ds = DataStore(self.spaces.ns)
        ds.put([rs_wsdl])        
        res = Resource()     
        res.ws_endpoint = "https://{0}.landexchange.vic.gov.au:8444/spear_a2a/services/LxSpearEcho".format(ENVIRONMENT)            
        res.client_cert_resource = client_cert
        res.soap_message = '''<?xml version="1.0" encoding="utf-8" ?><ns0:Envelope xmlns:ns0="http://schemas.xmlsoap.org/soap/envelope/"><ns0:Body><ns1:echo xmlns:ns1="http://was6.webservice.spear.lx.dse.vic.gov.au"><ns1:accessToken><ns2:accessLevel xmlns:ns2="http://access.webservice.spear.lx.dse.vic.gov.au">{0}</ns2:accessLevel><ns2:hostId xmlns:ns2="http://access.webservice.spear.lx.dse.vic.gov.au">{1}</ns2:hostId><ns2:hostPassword xmlns:ns2="http://access.webservice.spear.lx.dse.vic.gov.au">{2}</ns2:hostPassword><ns2:remoteUser xmlns:ns2="http://access.webservice.spear.lx.dse.vic.gov.au">{3}</ns2:remoteUser></ns1:accessToken><ns1:input>Hello, World!</ns1:input></ns1:echo></ns0:Body></ns0:Envelope>'''.format(self.spear_user_access_level, self.spear_user_username, self.spear_user_password, self.spear_user_remote_user)
        res.ws_name = ws_name
        # dummy task def resource
        task_def_resource = Resource()                
        a2a_task = A2ATask(self.spaces, uri_tasks.eplanning.spear.a2atask, task_def_resource)
        consumer_queue = Queue()     
        consumer_spaces_context = SpacesContext(self.spaces, consumer_queue)        
        consumer_spaces_context.put(uri_a2a.requests.abc, res)
        a2a_task.cb_issue_a2a_request('put', uri_a2a.requests.abc, uri_a2a.requests.abc, None, a2a_task.context)
        result = consumer_spaces_context.get(uri_a2a.requests.abc.response)
        self.assertEqual(result.echoResponse.echoReturn, 'Hello, World!')
        
    def test_spear_document_types_case_1(self):
        '''[a2atask] spear_document_types. '''
        uri_tasks = self.spaces.uri('tasks:')
        uri_spear = self.spaces.uri('spear:')
        uri_a2a = self.spaces.uri('a2a:')
        uri_datastore = self.spaces.uri('datastore:')  
        content_as_string = open(self.client_cert_file_name, 'rb').read()
        client_cert = Resource()
        client_cert.content = content_as_string
        client_cert.set_metadata(uri_datastore.resource.type, uri_spear.type.client_cert)
        client_cert.set_metadata(uri_spear.cert.password, self.client_cert_password)
        webservice_parameter = ResourceDict()
        getAll = []
        webservice_parameter['getAll'] = getAll 
        access_token_elements = [{'accessLevel':self.spear_user_access_level},
                                  {'hostId':self.spear_user_username},
                                  {'hostPassword':self.spear_user_password},
                                  {'remoteUser':self.spear_user_remote_user}]
        getAll.append({'accessToken':access_token_elements})
        res = Resource()
        res.data = webservice_parameter
        res.environment = ENVIRONMENT
        wsdl_file = open(self.wsdl_path + 'LxSpearDocumentTypes.wsdl', 'rb')
        wsdl_string = wsdl_file.read()
        wsdl = WSDL(wsdl_string)
        rs_wsdl = Resource()
        rs_wsdl.element_dictionary = wsdl.element_dictionary
        rs_wsdl.set_metadata(uri_datastore.resource.type, uri_spear.type.wsdl)
        rs_wsdl.set_metadata(uri_spear.wsdl.name, 'LxSpearDocumentTypes')
        ds = DataStore()
        ds.put([rs_wsdl, client_cert])    
        # dummy task def resource
        task_def_resource = Resource()                
        a2a_task = A2ATask(self.spaces, uri_tasks.eplanning.spear.a2atask, task_def_resource)
        a2a_task.start()
        time.sleep(1)
        consumer_callback_name = 'consumer_callback_name'
        consumer_queue = Queue()    
        consumer_spaces_context = SpacesContext(self.spaces, consumer_queue)          
        request_uri = consumer_spaces_context.put(uri_a2a.ws.LxSpearDocumentTypes.getAll.collection(True), res)
        dummy_callback_name = 'dummy_callback_name'
        dummy_queue = Queue()
        dummy_method_name = 'dummy_method_name'        
        dummy_spaces_context = SpacesContext(self.spaces, dummy_queue)
        consumer_spaces_context.watch_all(['put'], request_uri.collection(True), consumer_callback_name)
        consumer_spaces_context.delete(uri_tasks.eplanning.spear.a2atask)  
        (watch_all_callback, method, uri, return_value, result, caller_spaces_context, kwargs) = consumer_queue.get(True)
        response = consumer_spaces_context.get(return_value)
        self.assertNotEqual(caller_spaces_context, consumer_spaces_context)
        self.assertEqual(response.getAllResponse.getAllReturn.responseType.code, '000')
        self.assertEqual(kwargs, {})
        for document_type in response.getAllResponse.getAllReturn.documentTypes:
            if not document_type.name:
                self.fail('No document name specified')           

    def test_spear_document_types_case_2(self):
        '''[a2atask] spear_document_types invalid environment'''
        uri_tasks = self.spaces.uri('tasks:')
        uri_spear = self.spaces.uri('spear:')
        uri_a2a = self.spaces.uri('a2a:')
        uri_datastore = self.spaces.uri('datastore:')  
        content_as_string = open(self.client_cert_file_name, 'rb').read()
        client_cert = Resource()
        client_cert.content = content_as_string
        client_cert.set_metadata(uri_datastore.resource.type, uri_spear.type.client_cert)
        client_cert.set_metadata(uri_spear.cert.password, self.client_cert_password)
        webservice_parameter = ResourceDict()
        getAll = []
        webservice_parameter['getAll'] = getAll 
        access_token_elements = [{'accessLevel':self.spear_user_access_level},
                                  {'hostId':self.spear_user_username},
                                  {'hostPassword':self.spear_user_password},
                                  {'remoteUser':self.spear_user_remote_user}]
        getAll.append({'accessToken':access_token_elements})
        res = Resource()
        res.data = webservice_parameter
        res.environment = 'blah'
        wsdl_file = open(self.wsdl_path + 'LxSpearDocumentTypes.wsdl', 'rb')
        wsdl_string = wsdl_file.read()
        wsdl = WSDL(wsdl_string)
        rs_wsdl = Resource()
        rs_wsdl.element_dictionary = wsdl.element_dictionary
        rs_wsdl.set_metadata(uri_datastore.resource.type, uri_spear.type.wsdl)
        rs_wsdl.set_metadata(uri_spear.wsdl.name, 'LxSpearDocumentTypes')        
        ds = DataStore()
        ds.put([rs_wsdl, client_cert])    
        # dummy task def resource
        task_def_resource = Resource()                
        a2a_task = A2ATask(self.spaces, uri_tasks.eplanning.spear.a2atask, task_def_resource)
        a2a_task.start()
        time.sleep(1)
        consumer_callback_name = 'consumer_callback_name'
        consumer_queue = Queue()    
        consumer_spaces_context = SpacesContext(self.spaces, consumer_queue)          
        request_uri = consumer_spaces_context.put(uri_a2a.ws.LxSpearDocumentTypes.getAll.collection(True), res)
        dummy_callback_name = 'dummy_callback_name'
        dummy_queue = Queue()
        dummy_method_name = 'dummy_method_name'        
        dummy_spaces_context = SpacesContext(self.spaces, dummy_queue)
        consumer_spaces_context.watch_all(['put'], request_uri.collection(True), consumer_callback_name)
        consumer_spaces_context.delete(uri_tasks.eplanning.spear.a2atask)
        # wait 5 secs for a response to be placed in our queue. But because we used a invalid environment,
        # we should expect our queue to be empty when it timesout
        self.assertRaises(Empty, consumer_queue.get, True, 5)
    
    def test_spear_application_list(self):
        '''[a2atask] spear_application_list. '''
        uri_tasks = self.spaces.uri('tasks:')
        uri_spear = self.spaces.uri('spear:')
        uri_a2a = self.spaces.uri('a2a:')
        uri_datastore = self.spaces.uri('datastore:')  
        content_as_string = open(self.client_cert_file_name, 'rb').read()
        client_cert = Resource()
        client_cert.content = content_as_string
        client_cert.set_metadata(uri_datastore.resource.type, uri_spear.type.client_cert)
        client_cert.set_metadata(uri_spear.cert.password, self.client_cert_password)      
        webservice_parameter = ResourceDict()
        getAll = []
        webservice_parameter['getAll'] = getAll 
        access_token_elements = [{'accessLevel':self.spear_user_access_level},
                                  {'hostId':self.spear_user_username},
                                  {'hostPassword':self.spear_user_password},
                                  {'remoteUser':self.spear_user_remote_user}]
        getAll.append({'accessToken':access_token_elements})
        res = Resource()
        res.data = webservice_parameter
        res.environment = ENVIRONMENT
        wsdl_file = open(self.wsdl_path + 'LxSpearApplicationList.wsdl', 'rb')
        wsdl_string = wsdl_file.read()
        wsdl = WSDL(wsdl_string)
        rs_wsdl = Resource()
        rs_wsdl.element_dictionary = wsdl.element_dictionary
        rs_wsdl.set_metadata(uri_datastore.resource.type, uri_spear.type.wsdl)
        rs_wsdl.set_metadata(uri_spear.wsdl.name, 'LxSpearApplicationList')        
        ds = DataStore()
        ds.put([rs_wsdl, client_cert])    
        # dummy task def resource
        task_def_resource = Resource()                
        a2a_task = A2ATask(self.spaces, uri_tasks.eplanning.spear.a2atask, task_def_resource)
        a2a_task.log_level(LOGGING)        
        a2a_task.start()
        time.sleep(1)
        consumer_callback_name = 'consumer_callback_name'
        consumer_queue = Queue()    
        consumer_spaces_context = SpacesContext(self.spaces, consumer_queue)          
        request_uri = consumer_spaces_context.put(uri_a2a.ws.LxSpearApplicationList.getAll.collection(True), res)
        dummy_callback_name = 'dummy_callback_name'
        dummy_queue = Queue()
        dummy_method_name = 'dummy_method_name'        
        dummy_spaces_context = SpacesContext(self.spaces, dummy_queue)
        consumer_spaces_context.watch_all(['put'], request_uri.collection(True), consumer_callback_name)
        consumer_spaces_context.delete(uri_tasks.eplanning.spear.a2atask)  
        (watch_all_callback, method, uri, return_value, result, caller_spaces_context, kwargs) = consumer_queue.get(True)
        response = consumer_spaces_context.get(return_value)
        self.assertNotEqual(caller_spaces_context, consumer_spaces_context)
        self.assertEqual(response.getAllResponse.getAllReturn.responseType.code, '000') 
        
    def test_spear_user_2_0(self):
        '''[a2atask] spear_user_2_0. '''
        user_name = self.spear_user_username
        uri_tasks = self.spaces.uri('tasks:')
        uri_spear = self.spaces.uri('spear:')
        uri_a2a = self.spaces.uri('a2a:')
        uri_datastore = self.spaces.uri('datastore:')  
        content_as_string = open(self.client_cert_file_name, 'rb').read()
        client_cert = Resource()
        client_cert.content = content_as_string
        client_cert.set_metadata(uri_datastore.resource.type, uri_spear.type.client_cert)
        client_cert.set_metadata(uri_spear.cert.password, self.client_cert_password)
        webservice_parameter = ResourceDict()
        getDetails = []
        webservice_parameter['getDetails'] = getDetails 
        access_token_elements = [{'accessLevel':self.spear_user_access_level},
                                  {'hostId':self.spear_user_username},
                                  {'hostPassword':self.spear_user_password},
                                  {'remoteUser':self.spear_user_remote_user}]
        getDetails.append({'accessToken':access_token_elements})
        getDetails.append({'userId':user_name})
        res = Resource()
        res.data = webservice_parameter
        res.environment = ENVIRONMENT
        wsdl_file = open(self.wsdl_path + 'LxSpearUser_2_0.wsdl', 'rb')
        wsdl_string = wsdl_file.read()
        wsdl = WSDL(wsdl_string)
        rs_wsdl = Resource()
        rs_wsdl.element_dictionary = wsdl.element_dictionary
        rs_wsdl.set_metadata(uri_datastore.resource.type, uri_spear.type.wsdl)
        rs_wsdl.set_metadata(uri_spear.wsdl.name, 'LxSpearUser_2_0')        
        ds = DataStore()
        ds.put([rs_wsdl, client_cert])    
        # dummy task def resource
        task_def_resource = Resource()                
        a2a_task = A2ATask(self.spaces, uri_tasks.eplanning.spear.a2atask, task_def_resource)
        a2a_task.start()
        time.sleep(1)
        consumer_callback_name = 'consumer_callback_name'
        consumer_queue = Queue()    
        consumer_spaces_context = SpacesContext(self.spaces, consumer_queue)        
        request_uri = consumer_spaces_context.put(uri_a2a.ws.LxSpearUser_2_0.getDetails.collection(True), res)
        consumer_spaces_context.watch_all(['put'], request_uri.collection(True), consumer_callback_name)
        (watch_all_callback, method, uri, return_value, result, caller_spaces_context, kwargs) = consumer_queue.get(True)
        self.assertEqual(kwargs, {})
        consumer_spaces_context.delete(uri_tasks.eplanning.spear.a2atask)  
        response = consumer_spaces_context.get(return_value)
        self.assertNotEqual(caller_spaces_context, consumer_spaces_context)
        self.assertEqual(response.getDetailsResponse.getDetailsReturn.responseType.code, '000')
        self.assertEqual(response.getDetailsResponse.getDetailsReturn.user.userName, user_name)
        self.assertEqual(response.getDetailsResponse.getDetailsReturn.user.a2aUser, '1')
                      
    def test_spear_public_application(self):
        '''[a2atask] spear_public_application. '''
        uri_tasks = self.spaces.uri('tasks:')
        uri_spear = self.spaces.uri('spear:')
        uri_a2a = self.spaces.uri('a2a:')
        uri_datastore = self.spaces.uri('datastore:')  
        content_as_string = open(self.client_cert_file_name, 'rb').read()
        client_cert = Resource()
        client_cert.content = content_as_string
        client_cert.set_metadata(uri_datastore.resource.type, uri_spear.type.client_cert)
        client_cert.set_metadata(uri_spear.cert.password, self.client_cert_password)
        webservice_parameter = ResourceDict()
        getPublicApplicationDetails = []
        webservice_parameter['getPublicApplicationDetails'] = getPublicApplicationDetails 
        access_token_elements = [{'accessLevel':self.spear_user_access_level},
                                  {'hostId':self.spear_user_username},
                                  {'hostPassword':self.spear_user_password},
                                  {'remoteUser':self.spear_user_remote_user}]
        getPublicApplicationDetails.append({'accessToken':access_token_elements})
        getPublicApplicationDetails.append({'spearReference':'S004275P'})
        res = Resource()
        res.data = webservice_parameter
        res.environment = ENVIRONMENT
        wsdl_file = open(self.wsdl_path + 'LxSpearPublicApplication.wsdl', 'rb')
        wsdl_string = wsdl_file.read()
        wsdl = WSDL(wsdl_string)
        rs_wsdl = Resource()
        rs_wsdl.element_dictionary = wsdl.element_dictionary
        rs_wsdl.set_metadata(uri_datastore.resource.type, uri_spear.type.wsdl)
        rs_wsdl.set_metadata(uri_spear.wsdl.name, 'LxSpearPublicApplication')        
        ds = DataStore()
        ds.put([rs_wsdl, client_cert])    
        # dummy task def resource
        task_def_resource = Resource()                
        a2a_task = A2ATask(self.spaces, uri_tasks.eplanning.spear.a2atask, task_def_resource)
        a2a_task.start()
        time.sleep(1)
        consumer_callback_name = 'consumer_callback_name'
        consumer_queue = Queue()    
        consumer_spaces_context = SpacesContext(self.spaces, consumer_queue)        
        request_uri = consumer_spaces_context.put(uri_a2a.ws.LxSpearPublicApplication.getPublicApplicationDetails.collection(True), res)
        consumer_spaces_context.watch_all(['put'], request_uri.collection(True), consumer_callback_name)
        consumer_spaces_context.delete(uri_tasks.eplanning.spear.a2atask)        
        (watch_all_callback, method, uri, return_value, result, caller_spaces_context, kwargs) = consumer_queue.get(True)
        response = consumer_spaces_context.get(return_value)
        self.assertNotEqual(caller_spaces_context, consumer_spaces_context)
        self.assertNotEqual(response.getPublicApplicationDetailsResponse.getPublicApplicationDetailsReturn.responseType.code, '000')
        self.assertEqual(kwargs, {})         

    def test_spear_application_2_0(self):
        '''[a2atask] spear_application_2_0. '''
        user_name = self.spear_user_username
        uri_tasks = self.spaces.uri('tasks:')
        uri_spear = self.spaces.uri('spear:')
        uri_a2a = self.spaces.uri('a2a:')
        uri_datastore = self.spaces.uri('datastore:')  
        content_as_string = open(self.client_cert_file_name, 'rb').read()
        client_cert = Resource()
        client_cert.content = content_as_string
        client_cert.set_metadata(uri_datastore.resource.type, uri_spear.type.client_cert)
        client_cert.set_metadata(uri_spear.cert.password, self.client_cert_password)
        spear_reference = 'S005446B'
        webservice_parameter = ResourceDict()
        getApplication = []
        webservice_parameter['getApplication'] = getApplication 
        access_token_elements = [{'accessLevel':self.spear_user_access_level},
                                  {'hostId':self.spear_user_username},
                                  {'hostPassword':self.spear_user_password},
                                  {'remoteUser':self.spear_user_remote_user}]
        getApplication.append({'accessToken':access_token_elements})
        getApplication.append({'spearRef':spear_reference})
        res = Resource()
        res.data = webservice_parameter
        res.environment = ENVIRONMENT
        wsdl_file = open(self.wsdl_path + 'LxSpearApplication_2_0.wsdl', 'rb')
        wsdl_string = wsdl_file.read()
        wsdl = WSDL(wsdl_string)
        rs_wsdl = Resource()
        rs_wsdl.element_dictionary = wsdl.element_dictionary
        rs_wsdl.set_metadata(uri_datastore.resource.type, uri_spear.type.wsdl)
        rs_wsdl.set_metadata(uri_spear.wsdl.name, 'LxSpearApplication_2_0')        
        ds = DataStore()
        ds.put([rs_wsdl, client_cert])    
        # dummy task def resource
        task_def_resource = Resource()                
        a2a_task = A2ATask(self.spaces, uri_tasks.eplanning.spear.a2atask, task_def_resource)
        a2a_task.start()
        time.sleep(1)
        consumer_callback_name = 'consumer_callback_name'
        consumer_queue = Queue()    
        consumer_spaces_context = SpacesContext(self.spaces, consumer_queue)        
        request_uri = consumer_spaces_context.put(uri_a2a.ws.LxSpearApplication_2_0.getDetails.collection(True), res)
        consumer_spaces_context.watch_all(['put'], request_uri.collection(True), consumer_callback_name)
        (watch_all_callback, method, uri, return_value, result, caller_spaces_context, kwargs) = consumer_queue.get(True)
        self.assertEqual(kwargs, {})
        consumer_spaces_context.delete(uri_tasks.eplanning.spear.a2atask)  
        response = consumer_spaces_context.get(return_value)
        self.assertNotEqual(caller_spaces_context, consumer_spaces_context)
        self.assertEqual(response.getApplicationResponse.getApplicationReturn.responseType.code, '000')
        application = response.getApplicationResponse.getApplicationReturn.application
        self.assertEqual(application.declareOwnerOrNotifiedOwner, '1')
        self.assertEqual(application.chmpRequired, '0')
        self.assertEqual(application.permitCategories, [{'displayName': 'Subdivision land: 2', 'key': 'Subdivisionland2', 'permitCategoryType': 'SUBDIVISION'}])
        self.assertEqual(application.vcatReferenceNumber, None)
        self.assertEqual(application.applicantReferenceNumber, None)
        self.assertEqual(application.applicationType, 'PLANNING_PERMIT')
        self.assertTrue(int(application.ccVersion) > 0)
        self.assertEqual(application.clientName, 'HAF eDA Applicant A')
        self.assertEqual(application.councilDelegate, 'clause12')
        self.assertEqual(application.councilInternalReferenceNumbers, None)
        self.assertEqual(application.councilName, 'Port Phillip City Council')
        self.assertEqual(application.councilPlanningPermitNumber, None)
        self.assertEqual(application.councilReferenceNumber, '345')
        self.assertEqual(application.councilReferenceNumber2, None)
        self.assertEqual(application.covenantDecl1, 'no')
        self.assertEqual(application.covenantDeclComments, None)
        self.assertEqual(application.currentLandUsage, 'yada')
        self.assertEqual(application.developmentProposal, 'yada')
        self.assertTrue(len(application.documents) > 0)
        self.assertEqual(application.estateName, None)
        self.assertEqual(application.estimatedCost, '234')
        self.assertEqual(application.numberOfLots, '2')
        self.assertEqual(application.permitRequired, '-1')
        self.assertEqual(application.permitSpearRef, None)
        self.assertEqual(application.planNumber, None)
        self.assertEqual(application.proposalType, None)
        self.assertEqual(application.spearReference, spear_reference)
        self.assertEqual(application.stageNumber, None)
        self.assertEqual(application.attachedPlan, '0')
        self.assertEqual(application.certify1958, '0')
        self.assertEqual(application.declareInformationCorrect, '1')
        self.assertEqual(application.vcatFlag, '0')
        self.assertNotEqual(application.applicationState, None)
        self.assertTrue(application.applicant)
        self.assertEqual(application.applicantContact, 'anduse52')
        self.assertEqual(application.applicationCreator, 'anduse52')
        self.assertTrue(application.propertyOwners)
        self.assertEqual(application.applicationClassificationType, 'SUBDIVISION')
        self.assertEqual(application.culturalHeritageManagementPlanRequired, '0')
        self.assertEqual(application.preApplicationPlanningMeetingDate, None)
        self.assertEqual(application.preApplicationPlanningMeetingOccurred, '0')
        self.assertTrue(application.properties)
        
    def test_lxspeardocument_2_0(self):
        '''[a2atask] lxspeardocument_2_0. '''
        uri_tasks = self.spaces.uri('tasks:')
        uri_spear = self.spaces.uri('spear:')
        uri_a2a = self.spaces.uri('a2a:')
        uri_datastore = self.spaces.uri('datastore:')  
        content_as_string = open(self.client_cert_file_name, 'rb').read()
        client_cert = Resource()
        client_cert.content = content_as_string
        client_cert.set_metadata(uri_datastore.resource.type, uri_spear.type.client_cert)
        client_cert.set_metadata(uri_spear.cert.password, self.client_cert_password)
        document_id = '70077'
        version = '1'
        webservice_parameter = ResourceDict()
        getDocument = []
        webservice_parameter['getDocument'] = getDocument 
        access_token_elements = [{'accessLevel':self.spear_user_access_level},
                                  {'hostId':self.spear_user_username},
                                  {'hostPassword':self.spear_user_password},
                                  {'remoteUser':self.spear_user_remote_user}]
        getDocument.append({'accessToken':access_token_elements})
        getDocument.append({'documentId':document_id})
        getDocument.append({'version':version})
        res = Resource()
        res.data = webservice_parameter
        res.environment = ENVIRONMENT
        wsdl_file = open(self.wsdl_path + 'LxSpearDocument_2_0.wsdl', 'rb')
        wsdl_string = wsdl_file.read()
        wsdl = WSDL(wsdl_string)
        rs_wsdl = Resource()
        rs_wsdl.element_dictionary = wsdl.element_dictionary
        rs_wsdl.set_metadata(uri_datastore.resource.type, uri_spear.type.wsdl)
        rs_wsdl.set_metadata(uri_spear.wsdl.name, 'LxSpearDocument_2_0')        
        ds = DataStore()
        ds.put([rs_wsdl, client_cert])    
        # dummy task def resource
        task_def_resource = Resource()                
        a2a_task = A2ATask(self.spaces, uri_tasks.eplanning.spear.a2atask, task_def_resource)
        a2a_task.start()
        time.sleep(1)
        consumer_callback_name = 'consumer_callback_name'
        consumer_queue = Queue()    
        consumer_spaces_context = SpacesContext(self.spaces, consumer_queue)        
        request_uri = consumer_spaces_context.put(uri_a2a.ws.LxSpearDocument_2_0.getDocument.collection(True), res)
        consumer_spaces_context.watch_all(['put'], request_uri.collection(True), consumer_callback_name)
        consumer_spaces_context.delete(uri_tasks.eplanning.spear.a2atask)        
        (watch_all_callback, method, uri, return_value, result, caller_spaces_context, kwargs) = consumer_queue.get(True)
        response = consumer_spaces_context.get(return_value)
        self.assertNotEqual(caller_spaces_context, consumer_spaces_context)
        self.assertEqual(response.getDocumentResponse.getDocumentReturn.responseType.code, '000')
        self.assertTrue(response.getDocumentResponse.getDocumentReturn.document)
        self.assertEqual(kwargs, {})              

    def test_spear_organisation_getOrganisationDetails(self):
        '''[a2atask] spear_organisation_getOrganisationDetails. '''
        uri_tasks = self.spaces.uri('tasks:')
        uri_spear = self.spaces.uri('spear:')
        uri_a2a = self.spaces.uri('a2a:')
        uri_datastore = self.spaces.uri('datastore:')  
        content_as_string = open(self.client_cert_file_name, 'rb').read()
        client_cert = Resource()
        client_cert.content = content_as_string
        client_cert.set_metadata(uri_datastore.resource.type, uri_spear.type.client_cert)
        client_cert.set_metadata(uri_spear.cert.password, self.client_cert_password)
        webservice_parameter = ResourceDict()
        getOrganisationDetails = []
        webservice_parameter['getOrganisationDetails'] = getOrganisationDetails 
        access_token_elements = [{'accessLevel':self.spear_user_access_level},
                                  {'hostId':self.spear_user_username},
                                  {'hostPassword':self.spear_user_password},
                                  {'remoteUser':self.spear_user_remote_user}]
        getOrganisationDetails.append({'accessToken':access_token_elements})
        getOrganisationDetails.append({'key':'Port Phillip City Council'})
        res = Resource()
        res.data = webservice_parameter
        res.environment = ENVIRONMENT
        wsdl_file = open(self.wsdl_path + 'LxSpearOrganisation.wsdl', 'rb')
        wsdl_string = wsdl_file.read()
        wsdl = WSDL(wsdl_string)
        rs_wsdl = Resource()
        rs_wsdl.element_dictionary = wsdl.element_dictionary
        rs_wsdl.set_metadata(uri_datastore.resource.type, uri_spear.type.wsdl)
        rs_wsdl.set_metadata(uri_spear.wsdl.name, 'LxSpearOrganisation')
        ds = DataStore()
        ds.put([rs_wsdl, client_cert])    
        # dummy task def resource
        task_def_resource = Resource()                
        a2a_task = A2ATask(self.spaces, uri_tasks.eplanning.spear.a2atask, task_def_resource)
        a2a_task.start()
        time.sleep(1)
        consumer_callback_name = 'consumer_callback_name'
        consumer_queue = Queue()    
        consumer_spaces_context = SpacesContext(self.spaces, consumer_queue)          
        request_uri = consumer_spaces_context.put(uri_a2a.ws.LxSpearOrganisation.getOrganisationDetails.collection(True), res)
        dummy_callback_name = 'dummy_callback_name'
        dummy_queue = Queue()
        dummy_method_name = 'dummy_method_name'        
        dummy_spaces_context = SpacesContext(self.spaces, dummy_queue)
        consumer_spaces_context.watch_all(['put'], request_uri.collection(True), consumer_callback_name)
        consumer_spaces_context.delete(uri_tasks.eplanning.spear.a2atask)  
        (watch_all_callback, method, uri, return_value, result, caller_spaces_context, kwargs) = consumer_queue.get(True)
        response = consumer_spaces_context.get(return_value)
        self.assertNotEqual(caller_spaces_context, consumer_spaces_context)
        self.assertEqual(response.getOrganisationDetailsResponse.getOrganisationDetailsReturn.responseType.code, '000')
        self.assertEqual(kwargs, {})
        organisation = response.getOrganisationDetailsResponse.getOrganisationDetailsReturn.organisation
        self.assertEqual(organisation.siteType, 'Council')
        self.assertEqual(organisation.name, 'Port Phillip City Council')
                      
#    def test_lxspearlodgement_case_01(self):
#        '''[a2atask] lxspearlodgement rejectApplication. '''
#        uri_tasks = self.spaces.uri('tasks:')
#        uri_spear = self.spaces.uri('spear:')
#        uri_a2a = self.spaces.uri('a2a:')
#        uri_datastore = self.spaces.uri('datastore:')  
#        content_as_string = open(self.client_cert_file_name, 'rb').read()
#        client_cert = Resource()
#        client_cert.content = content_as_string
#        client_cert.set_metadata(uri_datastore.resource.type, uri_spear.type.client_cert)
#        client_cert.set_metadata(uri_spear.cert.password, self.client_cert_password)
#        pdf_file = open(self.attachments_path + 'Council/Reject Reason.pdf', 'rb')
#        pdf_string = pdf_file.read()
#        pdf_string_encoded = base64.b64encode('HaHa')
#        webservice_parameter = ResourceDict()
#        rejectApplication = []
#        webservice_parameter['rejectApplication'] = rejectApplication 
#        access_token_elements = [{'accessLevel':self.spear_user_access_level},
#                                  {'hostId':self.spear_user_username},
#                                  {'hostPassword':self.spear_user_password},
#                                  {'remoteUser':self.spear_user_remote_user}]
#        content_elements = [{'CDATA':pdf_string_encoded}]
#        full_document_elements = [{'documentType':'ApplicationAcceptanceRejection'},
#                                  {'content':content_elements}]
#        rejectApplication.append({'accessToken':access_token_elements})
#        rejectApplication.append({'spearReference':'S005702T'})
#        rejectApplication.append({'attachedDocument':full_document_elements})
#        rejectApplication.append({'applicationCcVersion':'16'})
#        res = Resource()
#        res.data = webservice_parameter
#        res.environment = ENVIRONMENT
#        wsdl_file = open(self.wsdl_path + 'LxSpearLodgement.wsdl', 'rb')
#        wsdl_string = wsdl_file.read()
#        wsdl = WSDL(wsdl_string)
#        rs_wsdl = Resource()
#        rs_wsdl.element_dictionary = wsdl.element_dictionary
#        rs_wsdl.set_metadata(uri_datastore.resource.type, uri_spear.type.wsdl)
#        rs_wsdl.set_metadata(uri_spear.wsdl.name, 'LxSpearLodgement')        
#        ds = DataStore()
#        ds.put([rs_wsdl, client_cert])    
#        # dummy task def resource
#        task_def_resource = Resource()                
#        a2a_task = A2ATask(self.spaces, uri_tasks.eplanning.spear.a2atask, task_def_resource)
#        a2a_task.log_level(LOGGING)
#        a2a_task.start()
#        time.sleep(1)
#        consumer_callback_name = 'consumer_callback_name'
#        consumer_queue = Queue()    
#        consumer_spaces_context = SpacesContext(self.spaces, consumer_queue)        
#        request_uri = consumer_spaces_context.put(uri_a2a.ws.LxSpearLodgement.rejectApplication.collection(True), res)
#        consumer_spaces_context.watch_all(['put'], request_uri.collection(True), consumer_callback_name)
#        consumer_spaces_context.delete(uri_tasks.eplanning.spear.a2atask)        
#        (watch_all_callback, method, uri, return_value, result, caller_spaces_context, kwargs) = consumer_queue.get(True)
#        response = consumer_spaces_context.get(return_value)
#        self.assertNotEqual(caller_spaces_context, consumer_spaces_context)
#        self.assertEqual(response.rejectApplicationResponse.rejectApplicationReturn.responseType.code, '000')
#        self.assertEqual(kwargs, {})
#               
#    def test_lxspearlodgement_case_02(self):
#        '''[a2atask] lxspearlodgement acceptApplication. '''
#        uri_tasks = self.spaces.uri('tasks:')
#        uri_spear = self.spaces.uri('spear:')
#        uri_a2a = self.spaces.uri('a2a:')
#        uri_datastore = self.spaces.uri('datastore:')  
#        content_as_string = open(self.client_cert_file_name, 'rb').read()
#        client_cert = Resource()
#        client_cert.content = content_as_string
#        client_cert.set_metadata(uri_datastore.resource.type, uri_spear.type.client_cert)
#        client_cert.set_metadata(uri_spear.cert.password, self.client_cert_password)
#        webservice_parameter = ResourceDict()
#        acceptApplication = []
#        webservice_parameter['acceptApplication'] = acceptApplication 
#        access_token_elements = [{'accessLevel':self.spear_user_access_level},
#                                  {'hostId':self.spear_user_username},
#                                  {'hostPassword':self.spear_user_password},
#                                  {'remoteUser':self.spear_user_remote_user}]
#        acceptApplication.append({'accessToken':access_token_elements})
#        acceptApplication.append({'spearReference':'S005633C'})
#        acceptApplication.append({'applicationCcVersion':'21'})
#        res = Resource()
#        res.data = webservice_parameter
#        res.environment = ENVIRONMENT
#        wsdl_file = open(self.wsdl_path + 'LxSpearLodgement.wsdl', 'rb')
#        wsdl_string = wsdl_file.read()
#        wsdl = WSDL(wsdl_string)
#        rs_wsdl = Resource()
#        rs_wsdl.element_dictionary = wsdl.element_dictionary
#        rs_wsdl.set_metadata(uri_datastore.resource.type, uri_spear.type.wsdl)
#        rs_wsdl.set_metadata(uri_spear.wsdl.name, 'LxSpearLodgement')        
#        ds = DataStore()
#        ds.put([rs_wsdl, client_cert])    
#        # dummy task def resource
#        task_def_resource = Resource()                
#        a2a_task = A2ATask(self.spaces, uri_tasks.eplanning.spear.a2atask, task_def_resource)
#        a2a_task.log_level(LOGGING)
#        a2a_task.start()
#        time.sleep(1)
#        consumer_callback_name = 'consumer_callback_name'
#        consumer_queue = Queue()    
#        consumer_spaces_context = SpacesContext(self.spaces, consumer_queue)        
#        request_uri = consumer_spaces_context.put(uri_a2a.ws.LxSpearLodgement.acceptApplication.collection(True), res)
#        consumer_spaces_context.watch_all(['put'], request_uri.collection(True), consumer_callback_name)
#        consumer_spaces_context.delete(uri_tasks.eplanning.spear.a2atask)        
#        (watch_all_callback, method, uri, return_value, result, caller_spaces_context, kwargs) = consumer_queue.get(True)
#        response = consumer_spaces_context.get(return_value)
#        self.assertNotEqual(caller_spaces_context, consumer_spaces_context)
#        self.assertEqual(response.acceptApplicationResponse.acceptApplicationReturn.responseType.code, '000')
#        self.assertEqual(kwargs, {})
#
#    def test_lxspearlodgement_case_03(self):
#        '''[a2atask] lxspearlodgement acceptPlanningApplicationWithChanges. '''
#        uri_tasks = self.spaces.uri('tasks:')
#        uri_spear = self.spaces.uri('spear:')
#        uri_a2a = self.spaces.uri('a2a:')
#        uri_datastore = self.spaces.uri('datastore:')  
#        content_as_string = open(self.client_cert_file_name, 'rb').read()
#        client_cert = Resource()
#        client_cert.content = content_as_string
#        client_cert.set_metadata(uri_datastore.resource.type, uri_spear.type.client_cert)
#        client_cert.set_metadata(uri_spear.cert.password, self.client_cert_password)
#        webservice_parameter = ResourceDict()
#        acceptPlanningApplicationWithChanges = []
#        webservice_parameter['acceptPlanningApplicationWithChanges'] = acceptPlanningApplicationWithChanges 
#        access_token_elements = [{'accessLevel':self.spear_user_access_level},
#                                  {'hostId':self.spear_user_username},
#                                  {'hostPassword':self.spear_user_password},
#                                  {'remoteUser':self.spear_user_remote_user}]
#        acceptPlanningApplicationWithChanges.append({'accessToken':access_token_elements})
#        acceptPlanningApplicationWithChanges.append({'spearReference':'S005650C'})
#        acceptPlanningApplicationWithChanges.append({'applicationCcVersion':'18'})
#        res = Resource()
#        res.data = webservice_parameter
#        res.environment = ENVIRONMENT
#        wsdl_file = open(self.wsdl_path + 'LxSpearLodgement.wsdl', 'rb')
#        wsdl_string = wsdl_file.read()
#        wsdl = WSDL(wsdl_string)
#        rs_wsdl = Resource()
#        rs_wsdl.element_dictionary = wsdl.element_dictionary
#        rs_wsdl.set_metadata(uri_datastore.resource.type, uri_spear.type.wsdl)
#        rs_wsdl.set_metadata(uri_spear.wsdl.name, 'LxSpearLodgement')        
#        ds = DataStore()
#        ds.put([rs_wsdl, client_cert])    
#        # dummy task def resource
#        task_def_resource = Resource()                
#        a2a_task = A2ATask(self.spaces, uri_tasks.eplanning.spear.a2atask, task_def_resource)
#        a2a_task.log_level(LOGGING)
#        a2a_task.start()
#        time.sleep(1)
#        consumer_callback_name = 'consumer_callback_name'
#        consumer_queue = Queue()    
#        consumer_spaces_context = SpacesContext(self.spaces, consumer_queue)        
#        request_uri = consumer_spaces_context.put(uri_a2a.ws.LxSpearLodgement.acceptPlanningApplicationWithChanges.collection(True), res)
#        consumer_spaces_context.watch_all(['put'], request_uri.collection(True), consumer_callback_name)
#        consumer_spaces_context.delete(uri_tasks.eplanning.spear.a2atask)        
#        (watch_all_callback, method, uri, return_value, result, caller_spaces_context, kwargs) = consumer_queue.get(True)
#        response = consumer_spaces_context.get(return_value)
#        self.assertNotEqual(caller_spaces_context, consumer_spaces_context)
#        self.assertEqual(response.acceptPlanningApplicationWithChangesResponse.acceptPlanningApplicationWithChangesReturn.responseType.code, '000')
#        self.assertEqual(kwargs, {})
#                                     
#    def test_lxspearcouncilreference(self):
#        '''[a2atask] lxspearcouncilreference addCouncilReferenceNumber. '''
#        uri_tasks = self.spaces.uri('tasks:')
#        uri_spear = self.spaces.uri('spear:')
#        uri_a2a = self.spaces.uri('a2a:')
#        uri_datastore = self.spaces.uri('datastore:')  
#        content_as_string = open(self.client_cert_file_name, 'rb').read()
#        client_cert = Resource()
#        client_cert.content = content_as_string
#        client_cert.set_metadata(uri_datastore.resource.type, uri_spear.type.client_cert)
#        client_cert.set_metadata(uri_spear.cert.password, self.client_cert_password)
#        webservice_parameter = ResourceDict()
#        addCouncilReferenceNumber = []
#        webservice_parameter['addCouncilReferenceNumber'] = addCouncilReferenceNumber 
#        access_token_elements = [{'accessLevel':self.spear_user_access_level},
#                                  {'hostId':self.spear_user_username},
#                                  {'hostPassword':self.spear_user_password},
#                                  {'remoteUser':self.spear_user_remote_user}]
#        addCouncilReferenceNumber.append({'accessToken':access_token_elements})
#        addCouncilReferenceNumber.append({'spearReference':'S005656B'})
#        addCouncilReferenceNumber.append({'councilReferenceNumber1':'01'})
#        addCouncilReferenceNumber.append({'councilReferenceNumber2':'02'})
#        addCouncilReferenceNumber.append({'delegateUsername':'clause12'})
#        addCouncilReferenceNumber.append({'applicationCcVersion':'27'})
#        res = Resource()
#        res.data = webservice_parameter
#        res.environment = ENVIRONMENT
#        wsdl_file = open(self.wsdl_path + 'LxSpearCouncilReference.wsdl', 'rb')
#        wsdl_string = wsdl_file.read()
#        wsdl = WSDL(wsdl_string)
#        rs_wsdl = Resource()
#        rs_wsdl.element_dictionary = wsdl.element_dictionary
#        rs_wsdl.set_metadata(uri_datastore.resource.type, uri_spear.type.wsdl)
#        rs_wsdl.set_metadata(uri_spear.wsdl.name, 'LxSpearCouncilReference')        
#        ds = DataStore()
#        ds.put([rs_wsdl, client_cert])    
#        # dummy task def resource
#        task_def_resource = Resource()                
#        a2a_task = A2ATask(self.spaces, uri_tasks.eplanning.spear.a2atask, task_def_resource)
#        a2a_task.log_level(LOGGING)
#        a2a_task.start()
#        time.sleep(1)
#        consumer_callback_name = 'consumer_callback_name'
#        consumer_queue = Queue()    
#        consumer_spaces_context = SpacesContext(self.spaces, consumer_queue)        
#        request_uri = consumer_spaces_context.put(uri_a2a.ws.LxSpearCouncilReference.addCouncilReferenceNumber.collection(True), res)
#        consumer_spaces_context.watch_all(['put'], request_uri.collection(True), consumer_callback_name)
#        consumer_spaces_context.delete(uri_tasks.eplanning.spear.a2atask)        
#        (watch_all_callback, method, uri, return_value, result, caller_spaces_context, kwargs) = consumer_queue.get(True)
#        response = consumer_spaces_context.get(return_value)
#        self.assertNotEqual(caller_spaces_context, consumer_spaces_context)
#        self.assertEqual(response.addCouncilReferenceNumberResponse.addCouncilReferenceNumberReturn.responseType.code, '000')
#        self.assertEqual(kwargs, {})                                   
#              
#    def test_lxspearreferapplication_case_01(self):
#        '''[a2atask] test_lxspearreferapplication setReferralsForApplication. '''
#        uri_tasks = self.spaces.uri('tasks:')
#        uri_spear = self.spaces.uri('spear:')
#        uri_a2a = self.spaces.uri('a2a:')
#        uri_datastore = self.spaces.uri('datastore:')  
#        content_as_string = open(self.client_cert_file_name, 'rb').read()
#        client_cert = Resource()
#        client_cert.content = content_as_string
#        client_cert.set_metadata(uri_datastore.resource.type, uri_spear.type.client_cert)
#        client_cert.set_metadata(uri_spear.cert.password, self.client_cert_password)
#        webservice_parameter = ResourceDict()
#        setReferralsForApplication = []
#        webservice_parameter['setReferralsForApplication'] = setReferralsForApplication 
#        access_token_elements = [{'accessLevel':self.spear_user_access_level},
#                                  {'hostId':self.spear_user_username},
#                                  {'hostPassword':self.spear_user_password},
#                                  {'remoteUser':self.spear_user_remote_user}]
#        referral_elements_A = [{'referralOption':'Section55'},
#                               {'raName':'HAF eDA RA A'},
#                               {'comment':'Comment for A'}]
#        referral_elements_B = [{'referralOption':'InfoOnly'},
#                               {'raName':'HAF eDA RA B'},
#                               {'comment':'Comment for B'}]                                
#        setReferralsForApplication.append({'accessToken':access_token_elements})
#        setReferralsForApplication.append({'spearReference':'S005656B'})
#        setReferralsForApplication.append({'referrals':referral_elements_A})
#        setReferralsForApplication.append({'referrals':referral_elements_B})
#        setReferralsForApplication.append({'applicationCcVersion':'55'})
#        res = Resource()
#        res.data = webservice_parameter
#        res.environment = ENVIRONMENT
#        wsdl_file = open(self.wsdl_path + 'LxSpearReferApplication.wsdl', 'rb')
#        wsdl_string = wsdl_file.read()
#        wsdl = WSDL(wsdl_string)
#        rs_wsdl = Resource()
#        rs_wsdl.element_dictionary = wsdl.element_dictionary
#        rs_wsdl.set_metadata(uri_datastore.resource.type, uri_spear.type.wsdl)
#        rs_wsdl.set_metadata(uri_spear.wsdl.name, 'LxSpearReferApplication')        
#        ds = DataStore()
#        ds.put([rs_wsdl, client_cert])    
#        # dummy task def resource
#        task_def_resource = Resource()                
#        a2a_task = A2ATask(self.spaces, uri_tasks.eplanning.spear.a2atask, task_def_resource)
#        a2a_task.log_level(LOGGING)
#        a2a_task.start()
#        time.sleep(1)
#        consumer_callback_name = 'consumer_callback_name'
#        consumer_queue = Queue()    
#        consumer_spaces_context = SpacesContext(self.spaces, consumer_queue)        
#        request_uri = consumer_spaces_context.put(uri_a2a.ws.LxSpearReferApplication.setReferralsForApplication.collection(True), res)
#        consumer_spaces_context.watch_all(['put'], request_uri.collection(True), consumer_callback_name)
#        consumer_spaces_context.delete(uri_tasks.eplanning.spear.a2atask)        
#        (watch_all_callback, method, uri, return_value, result, caller_spaces_context, kwargs) = consumer_queue.get(True)
#        response = consumer_spaces_context.get(return_value)
#        self.assertNotEqual(caller_spaces_context, consumer_spaces_context)
#        self.assertEqual(response.setReferralsForApplicationResponse.setReferralsForApplicationReturn.responseType.code, '000')
#        self.assertEqual(kwargs, {})  
#              
#    def test_lxspearreferapplication_case_02(self):
#        '''[a2atask] test_lxspearreferapplication setReferralsNotRequiredForApplication. '''
#        uri_tasks = self.spaces.uri('tasks:')
#        uri_spear = self.spaces.uri('spear:')
#        uri_a2a = self.spaces.uri('a2a:')
#        uri_datastore = self.spaces.uri('datastore:')  
#        content_as_string = open(self.client_cert_file_name, 'rb').read()
#        client_cert = Resource()
#        client_cert.content = content_as_string
#        client_cert.set_metadata(uri_datastore.resource.type, uri_spear.type.client_cert)
#        client_cert.set_metadata(uri_spear.cert.password, self.client_cert_password)
#        webservice_parameter = ResourceDict()
#        setReferralsNotRequiredForApplication = []
#        webservice_parameter['setReferralsNotRequiredForApplication'] = setReferralsNotRequiredForApplication 
#        access_token_elements = [{'accessLevel':self.spear_user_access_level},
#                                  {'hostId':self.spear_user_username},
#                                  {'hostPassword':self.spear_user_password},
#                                  {'remoteUser':self.spear_user_remote_user}]                           
#        setReferralsNotRequiredForApplication.append({'accessToken':access_token_elements})
#        setReferralsNotRequiredForApplication.append({'spearReference':'S005633C'})
#        setReferralsNotRequiredForApplication.append({'applicationCcVersion':'24'})
#        res = Resource()
#        res.data = webservice_parameter
#        res.environment = ENVIRONMENT
#        wsdl_file = open(self.wsdl_path + 'LxSpearReferApplication.wsdl', 'rb')
#        wsdl_string = wsdl_file.read()
#        wsdl = WSDL(wsdl_string)
#        rs_wsdl = Resource()
#        rs_wsdl.element_dictionary = wsdl.element_dictionary
#        rs_wsdl.set_metadata(uri_datastore.resource.type, uri_spear.type.wsdl)
#        rs_wsdl.set_metadata(uri_spear.wsdl.name, 'LxSpearReferApplication')        
#        ds = DataStore()
#        ds.put([rs_wsdl, client_cert])    
#        # dummy task def resource
#        task_def_resource = Resource()                
#        a2a_task = A2ATask(self.spaces, uri_tasks.eplanning.spear.a2atask, task_def_resource)
#        a2a_task.log_level(LOGGING)
#        a2a_task.start()
#        time.sleep(1)
#        consumer_callback_name = 'consumer_callback_name'
#        consumer_queue = Queue()    
#        consumer_spaces_context = SpacesContext(self.spaces, consumer_queue)        
#        request_uri = consumer_spaces_context.put(uri_a2a.ws.LxSpearReferApplication.setReferralsNotRequiredForApplication.collection(True), res)
#        consumer_spaces_context.watch_all(['put'], request_uri.collection(True), consumer_callback_name)
#        consumer_spaces_context.delete(uri_tasks.eplanning.spear.a2atask)        
#        (watch_all_callback, method, uri, return_value, result, caller_spaces_context, kwargs) = consumer_queue.get(True)
#        response = consumer_spaces_context.get(return_value)
#        self.assertNotEqual(caller_spaces_context, consumer_spaces_context)
#        self.assertEqual(response.setReferralsNotRequiredForApplicationResponse.setReferralsNotRequiredForApplicationReturn.responseType.code, '000')
#        self.assertEqual(kwargs, {})                                    
#              
#    def test_lxspearauthenticatedocument(self):
#        '''[a2atask] test_test_lxspearauthenticatedocument certifyDocument. '''
#        uri_tasks = self.spaces.uri('tasks:')
#        uri_spear = self.spaces.uri('spear:')
#        uri_a2a = self.spaces.uri('a2a:')
#        uri_datastore = self.spaces.uri('datastore:')  
#        content_as_string = open(self.client_cert_file_name, 'rb').read()
#        client_cert = Resource()
#        client_cert.content = content_as_string
#        client_cert.set_metadata(uri_datastore.resource.type, uri_spear.type.client_cert)
#        client_cert.set_metadata(uri_spear.cert.password, self.client_cert_password)
#        webservice_parameter = ResourceDict()
#        certifyDocument = []
#        webservice_parameter['certifyDocument'] = certifyDocument 
#        access_token_elements = [{'accessLevel':self.spear_user_access_level},
#                                  {'hostId':self.spear_user_username},
#                                  {'hostPassword':self.spear_user_password},
#                                  {'remoteUser':self.spear_user_remote_user}]
#        document_key_element_A = [{'documentCcVersion':'0'},
#                                  {'documentId':'74124'}
#                                  ]               
#        document_key_element_B = [{'documentCcVersion':'0'},
#                                  {'documentId':'74134'}
#                                  ]                           
#        certifyDocument.append({'accessToken':access_token_elements})
#        certifyDocument.append({'spearReference':'S005650C'})
#        certifyDocument.append({'documentKeys':document_key_element_A})
#        certifyDocument.append({'documentKeys':document_key_element_B})
#        res = Resource()
#        res.data = webservice_parameter
#        res.environment = ENVIRONMENT
#        wsdl_file = open(self.wsdl_path + 'LxSpearAuthenticateDocument.wsdl', 'rb')
#        wsdl_string = wsdl_file.read()
#        wsdl = WSDL(wsdl_string)
#        rs_wsdl = Resource()
#        rs_wsdl.element_dictionary = wsdl.element_dictionary
#        rs_wsdl.set_metadata(uri_datastore.resource.type, uri_spear.type.wsdl)
#        rs_wsdl.set_metadata(uri_spear.wsdl.name, 'LxSpearAuthenticateDocument')        
#        ds = DataStore()
#        ds.put([rs_wsdl, client_cert])    
#        # dummy task def resource
#        task_def_resource = Resource()                
#        a2a_task = A2ATask(self.spaces, uri_tasks.eplanning.spear.a2atask, task_def_resource)
#        a2a_task.log_level(LOGGING)
#        a2a_task.start()
#        time.sleep(1)
#        consumer_callback_name = 'consumer_callback_name'
#        consumer_queue = Queue()    
#        consumer_spaces_context = SpacesContext(self.spaces, consumer_queue)        
#        request_uri = consumer_spaces_context.put(uri_a2a.ws.LxSpearAuthenticateDocument.certifyDocument.collection(True), res)
#        consumer_spaces_context.watch_all(['put'], request_uri.collection(True), consumer_callback_name)
#        consumer_spaces_context.delete(uri_tasks.eplanning.spear.a2atask)        
#        (watch_all_callback, method, uri, return_value, result, caller_spaces_context, kwargs) = consumer_queue.get(True)
#        response = consumer_spaces_context.get(return_value)
#        self.assertNotEqual(caller_spaces_context, consumer_spaces_context)
#        self.assertEqual(response.certifyDocumentResponse.certifyDocumentReturn.responseType.code, '000')
#        self.assertEqual(kwargs, {})
#        
#    def test_spear_save_application(self):
#        '''[a2atask] spear_save_application. '''
#        uri_tasks = self.spaces.uri('tasks:')
#        uri_spear = self.spaces.uri('spear:')
#        uri_a2a = self.spaces.uri('a2a:')
#        uri_datastore = self.spaces.uri('datastore:')  
#        content_as_string = open(self.client_cert_file_name, 'rb').read()
#        client_cert = Resource()
#        client_cert.content = content_as_string
#        client_cert.set_metadata(uri_datastore.resource.type, uri_spear.type.client_cert)
#        client_cert.set_metadata(uri_spear.cert.password, self.client_cert_password)
#        webservice_parameter = ResourceDict()
#        saveApplication = []
#        webservice_parameter['saveApplication'] = saveApplication 
#        access_token_elements = [{'accessLevel':self.spear_user_access_level},
#                                  {'hostId':self.spear_user_username},
#                                  {'hostPassword':self.spear_user_password},
#                                  {'remoteUser':self.spear_user_remote_user}]
#        
#        council_address = [{'country':'Australia'},
#                             {'poBox':None},
#                             {'postcode':'3182'},
#                             {'postOfficeName':None},
#                             {'state':'Victoria'},
#                             {'streetName':'Carlisle'},
#                             {'streetNumber':'99a'},
#                             {'streetType':'Street'},
#                             {'suburb':'ST KILDA'},
#                             {'suffix':None},
#                             {'unitNumber':None},
#                             {'postalAddressType':None}
#                             ]
#                
#        council = [{'abn':'21762977945'},
#                   {'email1':'tony.allan@dse.vic.gov.au'},
#
#                   {'name':'Port Phillip City Council'},
#                   {'address':council_address},
#                   {'telephone':'(03) 9209 6777'},
#                   {'paymentGateway':None},
#                   {'mandatoryCouncilRa':None},
#                   {'optionalCouncilRa':'HAF eDA RA B'},
#                   {'id':'85'},
#                   {'suffix':'Port Phillip City Council'},
#                   {'email2':'tony.allan@dse.vic.gov.au'},
#                   {'faxNumber':None},
#                   {'publicEmail':'assist@portphillip.vic.gov.au'},
#                   {'ttyNumber':None},
#                   ]
#        overlay = [{'description':'43.01 Heritage'},
#                   {'name':'HO'},
#                   ]
#        zone = [{'description':'32.01 Residential 1'},
#                   {'name':'R1Z'},
#                   ]
#        property = [{'address':'14 BRIDGE STREET, PORT MELBOURNE VIC 3207'},
#                    {'block':None},
#                    {'council':council},
#                    {'cpn':'208179'},
#                    {'crownAllotment':None},
#                    {'crownBlock':None},
#                    {'crownParish':None},
#                    {'crownPortion':None},
#                    {'crownSection':None},
#                    {'crownSubdivision':None},
#                    {'crownTownship':None},
#                    {'existingPlanNumber':None},
#                    {'floorNumber':None},
#                    {'floorType':None},                    
#                    {'folioNumber':None},
#                    {'landataFullAddress':None},
#                    {'locationDesc':None},                        
#                    {'lotNumber':None},
#                    {'municipality':None},
#                    {'omissionReason':None},
#                    {'other':None},
#                    {'overlays':overlay},
#                    {'parcelPfi':None},                                      
#                    {'portion':None},
#                    {'postcode':'3207'},
#                    {'propertyName1':None},
#                    {'propertyName2':None},
#                    {'propertyPfi':None},
#                    {'section':None},
#                    {'spi':None},
#                    {'state':'VIC'},
#                    {'streetName':'BRIDGE'},
#                    {'streetNumber1':None},
#                    {'streetNumber2':None},
#                    {'streetSuffix':None},
#                    {'streetType':'STREET'},                    
#                    {'subdivision':None},
#                    {'suburb':'PORT MELBOURNE'},
#                    {'unitNumber1':None},
#                    {'unitNumber2':None},
#                    {'unitType':None},                                        
#                    {'volumeNumber':None},
#                    {'zones':zone},
#                    {'manuallyEntered':'0'},
#                    {'volFolType':'notapplicable'},
#                    ]
#        applicant_contact = [{'mobilePhone':None},
#                             {'homePhone':None},
#                             {'emailAddress':'tony.allan@dse.vic.gov.au'},
#                             {'businessPhone':'03 9637 9821'},
#                             {'surname':'A2A'},
#                             {'firstName':'Albert'},
#                             {'fax':None},
#                             {'contactTitle':'Prof'}
#                             ]
#        applicant_address = [{'country':'Australia'},
#                             {'poBox':None},
#                             {'postcode':'3002'},
#                             {'postOfficeName':None},
#                             {'state':'Victoria'},
#                             {'streetName':'Nicholoson'},
#                             {'streetNumber':'8'},
#                             {'streetType':'Street'},
#                             {'suburb':'East Melbourne'},
#                             {'suffix':None},
#                             {'unitNumber':'Level 9'},
#                             {'postalAddressType':None}
#                             ]
#        applicant = [{'contact':applicant_contact},
#                     {'organizationName':'HAF eDA Applicant A'},
#                     {'address':applicant_address}
#                     ]
#        application = [{'declareOwnerOrNotifiedOwner':False},
#                       {'chmpRequired':False},
#                       {'permitCategories':None},
#                       {'vcatReferenceNumber':None},
#                       {'applicantReferenceNumber':None},
#                       {'applicationType':'CERTIFICATION'},
#                       {'ccVersion':'1'},
#                       {'clientName':None},
#                       {'councilDelegate':None},
#                       {'councilInternalReferenceNumbers':None},
#                       {'councilName':None},
#                       {'councilPlanningPermitNumber':None},
#                       {'councilReferenceNumber':None},
#                       {'councilReferenceNumber2':None},
#                       {'covenantDecl1':'no'},
#                       {'covenantDeclComments':None},
#                       {'currentLandUsage':'yada'},
#                       {'developmentProposal':'yada'},
#                       {'documents':None},
#                       {'estateName':None},
#                       {'estimatedCost':'1234'},
#                       {'numberOfLots':'2'},
#                       {'permitRequired':'-1'},
#                       {'permitSpearRef':None},
#                       {'planNumber':None},
#                       {'proposalType':None},
#                       {'spearReference':None},
#                       {'stageNumber':None},
#                       {'attachedPlan':'0'},
#                       {'certify1958':'0'},
#                       {'declareInformationCorrect':'1'},
#                       {'vcatFlag':'0'},
#                       {'applicationState':'Draft'},
#                       {'applicant':applicant},
#                       {'applicantContact':'albaa049'},
#                       {'applicationCreator':'albaa049'},
#                       {'propertyOwners':applicant},
#                       {'applicationClassificationType':'SUBDIVISION'},
#                       {'culturalHeritageManagementPlanRequired':'0'},
#                       {'preApplicationMeetingCouncil':None},
#                       {'preApplicationPlanningMeetingDate':None},
#                       {'preApplicationPlanningMeetingOccurred':'0'},
#                       {'properties':property}
#                       ]
#        saveApplication.append({'accessToken':access_token_elements})
#        saveApplication.append({'application':application})
#        res = Resource()
#        res.data = webservice_parameter
#        res.environment = ENVIRONMENT
#        wsdl_file = open(self.wsdl_path + 'LxSpearSaveApplication.wsdl', 'rb')
#        wsdl_string = wsdl_file.read()
#        wsdl = WSDL(wsdl_string)
#        rs_wsdl = Resource()
#        rs_wsdl.element_dictionary = wsdl.element_dictionary
#        rs_wsdl.set_metadata(uri_datastore.resource.type, uri_spear.type.wsdl)
#        rs_wsdl.set_metadata(uri_spear.wsdl.name, 'LxSpearSaveApplication')        
#        ds = DataStore()
#        ds.put([rs_wsdl, client_cert])    
#        # dummy task def resource
#        task_def_resource = Resource()                
#        a2a_task = A2ATask(self.spaces, uri_tasks.eplanning.spear.a2atask, task_def_resource)
#        a2a_task.start()
#        time.sleep(1)
#        consumer_callback_name = 'consumer_callback_name'
#        consumer_queue = Queue()    
#        consumer_spaces_context = SpacesContext(self.spaces, consumer_queue)        
#        request_uri = consumer_spaces_context.put(uri_a2a.ws.LxSpearSaveApplication.saveApplication.collection(True), res)
#        consumer_spaces_context.watch_all(['put'], request_uri, consumer_callback_name)
#        consumer_spaces_context.delete(uri_tasks.eplanning.spear.a2atask)        
#        (watch_all_callback, method, uri, return_value, result, caller_spaces_context, kwargs) = consumer_queue.get(True)
#        response = consumer_spaces_context.get(return_value)
#        self.assertNotEqual(caller_spaces_context, consumer_spaces_context)
#        self.assertNotEqual(response.saveApplicationResponse.saveApplicationReturn.responseType.code, '000')
#        self.assertEqual(kwargs, {})    

    def create_wsdl_resource(self, wsdl_name, uri_datastore, uri_spear):
        wsdl_file = open(self.wsdl_path + wsdl_name +'.wsdl', 'rb')
        wsdl_string = wsdl_file.read()
        wsdl = WSDL(wsdl_string)
        rs_wsdl = Resource()
        rs_wsdl.element_dictionary = wsdl.element_dictionary
        rs_wsdl.set_metadata(uri_datastore.resource.type, uri_spear.type.wsdl)
        rs_wsdl.set_metadata(uri_spear.wsdl.name, wsdl_name)
        return rs_wsdl
    
if __name__ == "__main__":
    #import sys;sys.argv = ['', 'Test.testName']
    unittest.main()